package com.hxx.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hxx.entity.StationEntity;
import com.hxx.service.StationService;
import com.hxx.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/station")
public class StationController {
    @Autowired
    private StationService stationService;

    @GetMapping("page")
    public R listPage(Page page, StationEntity station) {
        stationService.listPage(page, station);
        return R.ok().data("list",page.getRecords())
                .data("total",page.getTotal());
    }

    @PostMapping("add")
    public R add(@RequestBody StationEntity station) {
        stationService.save(station);
        return R.ok();
    }

    @PutMapping("update")
    public R update(@RequestBody StationEntity station) {
        stationService.updateById(station);
        return R.ok();
    }

    @DeleteMapping("delete/{id}")
    public R delete(@PathVariable Long id) {
        stationService.removeById(id);
        return R.ok();
    }

    @GetMapping("all")
    public R list() {
        return R.ok().data("list",stationService.list());
    }
}























